const app = getApp();
const AJAX = app.$ajax,
  $wx = app.$wx;

Page({
  data: {
    page: 1
  },

  onLoad(){
    this.getMsg();
  },

  onShareAppMessage(){

  },

  setMsg(e){
    let _this = this, ed = e.currentTarget.dataset;
    
    AJAX.setMsg({
      loadType: 'default',
      loadMsg: '加载中...',
      id: ed.item.id
    }).then(([status, res, msg]) => {
      $wx.showToast(msg, {
        success(){
          if(status){
            _this.getMsg();
          }
        }
      });
    });
  },

  /**
   * 获取系统消息
   * @param page
   * */ 
  getMsg(){
    let td = this.data;
    AJAX.getMsg({
      loadType: 'bar',
      page: td.page
    }).then(([status, res, msg]) => {
      console.log(res);
      if(status){
        this.setData({
          msgList: res.data
        });
      }else{
        $wx.showToast(msg);
      }
    });
  }
});